import numpy as np

def benchmarks_lib(num,x,npar):
    #Data:2020/09/03
    #Read me:This is some benchmarks that can be used to test the optimization
    #algorithms.

    ## unimodal benchmark functions
    if num == 1:  #[-100,100]
        y = np.sum((x-2)**2)

    if num == 2:     #[-10,10]
        temp = 1
        for ii in np.arange(npar):
            temp = temp * np.abs(x[ii])
        y = np.sum(np.abs(x)) + temp

    if num == 3:     #[-100,100]
        y = 0
        for ii in np.arange(npar):
            for jj in np.arange(ii):
                y1 = np.sum(x[jj])
            y1 = y1**2
            y = y + y1

    if num == 4:   #[-100,100]
        y = np.sum((x+0.5)**2)

    if num == 5:  #[-1.28,1.28]
        t1 = 0
        for ii in np.arange(npar):
            t1 = t1 + ii * x[ii]**4
        y = t1 + np.random.rand()


    ## multimodal benchmark functions
    if num ==  6:  #0
        y = sum(x**2 - 10 * np.cos(2* np.pi *x) + 10)

    if num == 7:   #0
        y = -20 * np.exp(-0.2 * np.sqrt(np.sum(x**2)/npar)) - np.exp(np.sum(np.cos(2*np.pi*x))/npar) + 20 + np.exp[0]

    if num ==8:  #0
        y1 = 1
        for ii in np.arange(npar):
            y1 = y1 * np.cos(x[ii]/np.sqrt(ii))
        y = np.sum(x**2) / 4000 - y1 + 1

    ## fixed-dimension multimodal benchmark functions
    if num==9:  #3
        y1 = 1 + (x[0] + x[1] + 1)**2 * (19 - 14*x[0] + 3 * x[0]**2 - 14*x[1] + 6 * x[0] * x[1] + 3*x[1]**2)
        y2 = 30 + (2*x[0] - 3*x[1])**2 * (18 - 32*x[0] + 12*x[0]**2 + 48*x[1] - 36*x[0]*x[1] + 27 * x[1]**2)
        y = y1*y2

    if (num==10):#Schaffer function N. 2   0
        y = 0.5 + ((np.sin(x[0]**2-x[1]**2))**2 - 0.5) / (1+0.001*(x[0]**2+x[1]**2))**2

    if (num == 11): #Schaffer  -1
        x1=x[0]  
        y1=x[1]  
        temp=x1**2+y1**2  
        f=0.5-(np.sin(np.sqrt(temp))**2-0.5)/(1+0.001*temp)**2  
        y=-f
